<template>
	<om-formsub-outer :index="index"  :confirmBtn="!checkedit" :checkedit="checkedit">
		<om-autoform ref="autoform" :checkedit="checkedit"  :initConfigData="autoformdata" :initValue="initValue"></om-autoform>
	</om-formsub-outer>
</template>

<script>
	import {subOnLoad, changeEditor,configSelectData} from '../../../static/js/formUtil.js';
	import urlUtil from '@/static/js/urlUtil.js';
	export default {
		provide() {
			return {
				formPage: this
			};
		},
		data() {
			return {
				checkedit:false,
				initValue:{
					userId:"",
					userName:"",
					postId:"",
					postName:"",
					instId:"",
					instName:""
				},
				autoformdata: [],
				cachename:'',
				index:null,
				datas:[],
				order:0,
				formdata:{},
				postId:"",
				userpostCacheKey:"adm-meet-summary-data-info-title8-userpost-cache",
			}
		},
		methods: {
			onSelectUserPost(data){
				var row = this.$refs.autoform.formdata
				row.userId = data.userId;
				row.userName = data.userName;
				row.postId = data.posId;
				row.postName = data.posName;
			},
			initLoad(){
				let _that = this
				var ajaxArr = [
					urlUtil.dictZeroComboboxUrl('38163'), //特性分类
					urlUtil.dictZeroComboboxUrl('38184')//补充代号
				];
				urlUtil.promiseAll(ajaxArr, function(res){
					_that.$refs.autoform.changeEditor("title7","traitTypeId",{
						data:configSelectData(res[0],"id","dicname")
					})
					_that.$refs.autoform.changeEditor("title7","supplyCodeId",{
						data:configSelectData(res[1],"id","dicname")
					})
				})
				changeEditor('title8', "userPostId", {
					"link":"/pages/public/pageSearch/pageSearch",
					"linkParam": {
						namefield:"userPosInstName",
						searchfield:"q",
						url:urlUtil.officePageUrl().url,
						cachename:_that.userpostCacheKey,
						placeholder:"请输入姓名、岗位、机构"
					}
				},null,_that.autoformdata)
			}
		},
		onLoad(e){
			//设计评审相关内容
			let _that = this
			subOnLoad(_that, e, function() {
				_that.postId = e.postId
				if(e.configDataCacheKey){
					uni.getStorage({
						key: e.configDataCacheKey,
						success: function(res) {
							//if(res.data && res.data instanceof Array){
							if(res.data && Object.prototype.toString.call(res.data)==='[object Array]'){
								_that.autoformdata = res.data
								Object.assign(_that.initValue, _that.formdata)
								_that.autoformdata[0].order = _that.order
								_that.initLoad()
							}
						}
					});
				}
			})
		},
		onShow(){
			let _that = this
			if(_that.$refs.autoform){
				uni.getStorage({
					key: this.userpostCacheKey,
					success: function(res) {
						if(res.data){
							let d = res.data
							var formdata  = _that.$refs.autoform.formdata
							formdata.userPostId = d.id
							formdata.userPostName = d.userPosInstName
							formdata.userId = d.userId
							formdata.userName = d.userName
							formdata.postId = d.posId
							formdata.postName = d.posName
							formdata.instId = d.instId
							formdata.instName = d.instName
							uni.removeStorage({
								key: _that.userpostCacheKey
							});
						}
					}
				});
			}
		}
	}
</script>
